$(document).ready(function() {
	$.ajaxSetup({
		cache : false
	});
	$(document).ajaxSend(function(e, xhr, opt) {
		showAjaxLoadingCover("loading");
	});
	$(document).ajaxSuccess(function(e, xhr, opt) {
		try {
			var response = eval("(" + xhr.responseText + ")");
			if (!response.success) {
				hide = false;
				if ($("#user-login-form-div").html() == "") {
					if (response.errorCode == 10020) {
						$("#user-login-form-div").load("/admin/login/");
					} else if (response.errorCode == 10040) {
						$("#user-login-form-div").load("/admin/setup/");
					}
				}
			}
		} catch (e) {
		}
		hideAjaxLoadingCover("success");
	});
	$(document).ajaxError(function(event, xhr, options, exc) {
		showAjaxLoadingCover("server error");
	});
	LG.getUser(function(json) {
		if (json.success) {
			$("#login-user-name").html(eval("(" + json.data + ")").name);
		}
	});
	$("#sidebar a").click(function() {
		$("#main_content").load($(this).attr("href"));
		return false;
	});
});
function logout() {
	LG.logout(function() {
		location.reload();
	});
}
function showAjaxLoadingCover(message) {
	$("#ajax-loading-cover-message").html(message);
	$("#ajax-loading-cover").show();
}
function hideAjaxLoadingCover(message) {
	$("#ajax-loading-cover-message").html(message);
	setTimeout(function() {
		$("#ajax-loading-cover").hide();
	}, 500);
}